#ifndef BOOTLOADER_H
#define BOOTLOADER_H

#include <stdint.h>
#include "xprintf.h"

#define info(...) xprintf(__VA_ARGS__)
//#define info(...)

#ifdef DEBUG
#define debug(...) xprintf(__VA_ARGS__)
//#define debug(...)
#else
#define debug(...)
#endif // #ifdef DEBUG

/*
 -----0x00100FFF-----  BL_END
|                   |
|                   |  4 KB
|                   |
 -----0x00100000-----  BL_ENTRY
*/
#define BL_ENTRY		FMC_LDROM_BASE
#define BL_SIZE			(4 * 1024)

/*
 -----0x0000FFFF-----  SHARE_END
|                   |
|                   |  0.5 KB
|                   |
 -----0x0000FE00-----  SHARE_ENTRY
|                   |
|                   |  3.5 KB
|                   |
 -----0x0000F000-----  CFG_ENTRY
|                   |
|                   |  30 KB
|                   |
 -----0x00007800-----  FW_ENTRY / DF_BASE
|                   |
|                   |  30 KB
|                   |
 -----0x00000000-----  AP_ENTRY
*/
#define AP_ENTRY		FMC_APROM_BASE
#define AP_SIZE			(30 * 1024)

#define DF_BASE			(AP_ENTRY + AP_SIZE)	

#define FW_ENTRY		DF_BASE
#define FW_SIZE			(30 * 1024)

#define CFG_ENTRY		(FW_ENTRY + FW_SIZE)
#define CFG_SIZE		(3 * 1024 + 512)	

#define SHARE_ENTRY		(CFG_ENTRY + CFG_SIZE)
#define SHARE_SIZE		(512)

typedef struct {
	uint32_t fw_size;
	uint32_t fw_crc;
	uint32_t need_update;
	uint32_t this_crc;
} T_Share;

typedef void (FUNC_ENTRY)(void);

#endif  // BOOTLOADER_H

